﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>

</head>
<body>
    <button onclick="getdata(1)">all send</button>
    <button onclick="getdata(0)">before send</button>
    <textarea id="tx"></textarea>
</body>

</html>
<script src="signalr.js"></script>
<script>
    const connection = new signalR.HubConnectionBuilder()
        .withUrl("/sr")
        .configureLogging(signalR.LogLevel.Trace)
        .withAutomaticReconnect()
        .build();

    async function start() {
        try {
            await connection.start();
            console.log("SignalR Connected.");
        } catch (err) {
            console.log(err);
            //setTimeout(start, 5000);
        }
    };

    //connection.onclose(start);

    // Start the connection.
    start();

    //接收数据逻辑
    function getdata(all) {
        console.log("connected");
        connection.invoke("SvcInfo", 'jstest',all).then(p => console.log(p)).catch(err => console.error(err.toString()));
    };
    connection.on("NewMsg", function (msg) {
        tx.value += "\r\n" + msg
        console.log(msg);
    });
</script>